monk = require "monk"

prefix = process.env.APPID + "_"
DB = monk process.env.MONGODB


remonk = (url)->
  DB = monk url or process.env.MONGODB

ADMIN = DB.get prefix + "admin"
SETTING = DB.get prefix + "setting"
BOT = DB.get prefix + "bot"
ORDER = DB.get prefix + "order"
CONTACT = DB.get prefix + "contact"
MESSAGE = DB.get prefix + "message"
SEND = DB.get prefix + "send"
SHORTLINK = DB.get prefix + "shortlink"
REMOVED = DB.get prefix + "removed"
REDEEM = DB.get prefix + "redeem"
SESSION = DB.get prefix + "session"

CLIENT = DB.get prefix + "client"
CLIENT_CHARGE_LOG = DB.get prefix + "room_charge_log"
CLIENT_RED_LOG = DB.get prefix + "room_red_log"
USER = DB.get prefix + "user"

ROOM = DB.get prefix + "room"
ROOM_CONTACT = DB.get prefix + "room_contact"
ROOM_INVITE = DB.get prefix + "room_invite"

POINT_RULE = DB.get prefix + "point_rule"
POINT_DATA = DB.get prefix + "point_data"
POINT_LOG = DB.get prefix + "point_log"
POINT_ITEM = DB.get prefix + "point_item"
POINT_DRAW = DB.get prefix + "point_draw"
POINT_ORDER = DB.get prefix + "point_order"

# POINT_RULE.find({}, $set: invite_notify: true, sign_notify: true).then console.log

getMainSetting = (clientid) ->
  setting = await SETTING.findOne id: "main"
  clientSetting = {}
  if clientid
    client = await CLIENT.findOne clientid
    clientSetting = client.setting
  _default =
    welcomeimage: "https://eva0.bot.qw360.cn/img/create-room.png"
    welcometips: """
        欢迎使用建群精灵，请根据以下步骤进行操作：
        1： 点击右上角【 ... 】选择添加任意一好友即可立即创建一个群聊。
        2：创建好群聊后，群内发送任意文字激活群聊。
        3：稍后我会给你下发设置连接，点击链接设置群规则。
        👉查看使用教程 #公众号：建群精灵 
        【请根据以下流程创建群聊】 
        """
    joinroomtips: "入群成功, 记得到私聊页面设置本群积分规则"
    signtips: """恭喜您签到成功，获得 {{签到积分}} 积分，您当前可用积分为 {{现有积分}}

        👉立即兑换奖品：{{兑换地址}}
        """

    invitetips: """
      您成功邀请好友入群，获得 {{邀请积分}} 积分，您当前可用积分为{{现有积分}}

      👉立即兑换奖品：{{兑换地址}}
      """

  return Object.assign _default, setting, clientSetting

module.exports =
  remonk: remonk
  getMainSetting: getMainSetting
  BOT: BOT
  CONTACT: CONTACT
  SETTING: SETTING
  SESSION: SESSION
  ORDER: ORDER
  USER: USER
  MESSAGE: MESSAGE
  SEND: SEND
  SHORTLINK: SHORTLINK
  REMOVED: REMOVED
  CLIENT: CLIENT
  CLIENT_CHARGE_LOG: CLIENT_CHARGE_LOG
  ROOM: ROOM
  ROOM_CONTACT: ROOM_CONTACT
  ROOM_INVITE: ROOM_INVITE
  POINT_RULE: POINT_RULE
  POINT_DATA: POINT_DATA
  POINT_LOG: POINT_LOG
  POINT_ITEM: POINT_ITEM
  POINT_DRAW: POINT_DRAW
  POINT_ORDER: POINT_ORDER
  REDEEM: REDEEM
